<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.4"/>
<title>SPI Driver: SPI Driver for MPC5604B_MV27</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">SPI Driver
   &#160;<span id="projectnumber">1.1</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.4 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li class="current"><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('index.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">SPI Driver for MPC5604B_MV27 </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="intro_sec"></a>
About</h1>
<pre class="fragment">This driver provides a simple user interface for using
the three DSPI modules on this microcontroller. It provides
high level data transfer functions that can run on either background
or foreground, using Transfer Complete interrupts as needed.

A lot of flexibility is still available to the user via some Macros for
modifying Transfer and Data attributes, or with a lot of different transfer
methods for different needs.

The following code shows how the module is used:
</pre><div class="fragment"><div class="line"><span class="keyword">struct </span><a class="code" href="struct___s_p_i___d_r_v.html">_SPI_DRV</a> <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[];          <span class="comment">//SPI variable has to be imported from the SPI Driver module, do not forget this line!</span></div>
<div class="line">uint16_t RxData[128];           <span class="comment">//An array for storing received data</span></div>
<div class="line">uint16_t i;                     <span class="comment">//A dummy variable.</span></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>) {</div>
<div class="line">    initModesAndClks();     <span class="comment">//remember to enable DSPI module with PCTL registers, and set Sys_Clk(=Peripheral_Clock) to 64MHz</span></div>
<div class="line">                            <span class="comment">//if you wish to use predefined baud-rates</span></div>
<div class="line">    initPeriClkGen();            </div>
<div class="line">    disableWatchdog();           </div>
<div class="line">    <a class="code" href="group__group5.html#gaa3f08b6b790aa1596d6f41a122c17aad" title="Initialisation function for SPI driver. Initializes the SPI variable with appropriate assingments on ...">initialise_SPI_DRIVER</a>();        <span class="comment">//must be called before using the driver</span></div>
<div class="line">    enableIrq();</div>
<div class="line">    </div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].<a class="code" href="struct___s_p_i___d_r_v.html#aead12928b2c4e6898c71c73b32315770" title="Initiatlisation method. Must be called before using the driver. . ">init</a>(SPI_BAUD_62500, <a class="code" href="group__group2.html#ga9b5018e9d6279fd4f2416aa3891fb106" title="Default values specified at baud rate of 62500Hz (or higher) for the driver, system clock being 64MHz...">SPI_DELAY_DEFAULT</a>); <span class="comment">//Initialise SPI module you wish to use, in this example PORT_A of DSPI0 is defined</span></div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].<a class="code" href="struct___s_p_i___d_r_v.html#aead12928b2c4e6898c71c73b32315770" title="Initiatlisation method. Must be called before using the driver. . ">init</a>(SPI_BAUD_62500, <a class="code" href="group__group2.html#ga9b5018e9d6279fd4f2416aa3891fb106" title="Default values specified at baud rate of 62500Hz (or higher) for the driver, system clock being 64MHz...">SPI_DELAY_DEFAULT</a>); <span class="comment">//and PORT_E of DSPI1, and they are connected with jumper wires.</span></div>
<div class="line">    </div>
<div class="line">    <span class="comment">//Following lines test the driver with different methods and changing</span></div>
<div class="line">    <span class="comment">//DSPI modules roles as it goes (master/slave, tx/rx etc..). At the end of the</span></div>
<div class="line">    <span class="comment">//program you can check the memory map, @RxData and see if there has been any undesirable behaviours.</span></div>
<div class="line">    <span class="comment">//For instance, it is practical for setting right values for the Delay Attributes.</span></div>
<div class="line">    </div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].<a class="code" href="struct___s_p_i___d_r_v.html#a5f87e1c352b3224fe2a6bed5db0ccf12" title="Read data array, given size (Slave). Allows a half-duplex data transmission where the module will rec...">listen</a>(RxData, 6,1);     <span class="comment">//Here listen is running on the background, after each frame transfer</span></div>
<div class="line">                                    <span class="comment">//an interrupt incerements RX_Index and waits for the next data to be received.</span></div>
<div class="line">                                    <span class="comment">//Useful for a slave device waiting for commands.</span></div>
<div class="line">    <span class="keywordflow">for</span>(i=0xA500;i&lt;0xA509;i++)</div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].<a class="code" href="struct___s_p_i___d_r_v.html#a247fbfc90fac794d9c14e81848e53443" title="Write data (Master). Allows a half-duplex data transmission where the module will transmit a 16-bit d...">write</a>(&amp;i);           <span class="comment">//Write a single data, runs only on foreground. Can be used to send quick commands.</span></div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">while</span> (!(<a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].<a class="code" href="struct___s_p_i___d_r_v.html#a76c0ed371181cdc8f053170de8144ca2">Completed</a> &amp;&amp; <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].<a class="code" href="struct___s_p_i___d_r_v.html#a76c0ed371181cdc8f053170de8144ca2">Completed</a>)){}   <span class="comment">//Always wait for things to be completed when using background methods.</span></div>
<div class="line"></div>
<div class="line"></div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].<a class="code" href="struct___s_p_i___d_r_v.html#adca794807f12ed1014f0e08fbf17c695" title="Read data array, given terminating data (Slave). Allows a half-duplex data transmission where the mod...">listen_till</a>((RxData+6), 0x5A1F,1);       <span class="comment">//This time listen method runs until a specific data is received.</span></div>
<div class="line">                                                    <span class="comment">//Would be practical for using on ascii transmissions ending with &#39;\0&#39;.</span></div>
<div class="line">    <span class="keywordflow">for</span>(i=0x5A00;i&lt;0x5A2F;i++)</div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].<a class="code" href="struct___s_p_i___d_r_v.html#a247fbfc90fac794d9c14e81848e53443" title="Write data (Master). Allows a half-duplex data transmission where the module will transmit a 16-bit d...">write</a>(&amp;i);</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">while</span> (!(<a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].Completed &amp;&amp; <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].Completed)){}</div>
<div class="line"></div>
<div class="line">    </div>
<div class="line">    i=0xD6E1;</div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].<a class="code" href="struct___s_p_i___d_r_v.html#a086ad89b79b23005b984e80dc5e65b92" title="Write data (Slave). The module will write the data to its TX_Buffer as a slave, ready to be read by a...">show</a>(&amp;i,1);                              <span class="comment">//show method, running on the background, places a singla data on TX Buffer</span></div>
<div class="line">                                                    <span class="comment">//and when the transfer is completed, an interrupt updates its flags.</span></div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].<a class="code" href="struct___s_p_i___d_r_v.html#a0394bc0b91f6bb1a769c0f6added863a" title="Read data (Master). Allows a half-duplex data transmission where the module will receive a 16-bit dat...">read</a>(RxData+40);                         <span class="comment">//Read method, receives specific data from a slave. Could be used to</span></div>
<div class="line">                                                    <span class="comment">//get a chip&#39;s status.</span></div>
<div class="line">    <span class="keywordflow">while</span> (!(<a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].Completed &amp;&amp; <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].Completed)){}</div>
<div class="line">    </div>
<div class="line">    i=0x0666;                                       <span class="comment">//Roles are inverted now, to check if any bugs related to the driver exists.</span></div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].<a class="code" href="struct___s_p_i___d_r_v.html#a086ad89b79b23005b984e80dc5e65b92" title="Write data (Slave). The module will write the data to its TX_Buffer as a slave, ready to be read by a...">show</a>(&amp;i,1);                              <span class="comment">//Methods set the modules to master or to slave according to their needs.</span></div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].<a class="code" href="struct___s_p_i___d_r_v.html#a0394bc0b91f6bb1a769c0f6added863a" title="Read data (Master). Allows a half-duplex data transmission where the module will receive a 16-bit dat...">read</a>(RxData+45);</div>
<div class="line">    <span class="keywordflow">while</span> (!(<a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].Completed &amp;&amp; <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].Completed)){}</div>
<div class="line"></div>
<div class="line">    </div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].<a class="code" href="struct___s_p_i___d_r_v.html#a5f87e1c352b3224fe2a6bed5db0ccf12" title="Read data array, given size (Slave). Allows a half-duplex data transmission where the module will rec...">listen</a>((RxData+50), 4,1);                <span class="comment">//Now both modules are running on the background, &#39;write array&#39; get the next half word</span></div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].<a class="code" href="struct___s_p_i___d_r_v.html#a41173e3adcf94d40c1aaa34767bf638f" title="Write data array (Master). Allows a half-duplex data transmission where the module will transmit an a...">write_array</a>((uint16_t*)<span class="stringliteral">&quot;Coucou!\0&quot;</span>,4,1); <span class="comment">//when the current one is transmitted and &#39;listen&#39; manages the RX array.</span></div>
<div class="line">                                                    <span class="comment">//In real situations, it would be absur to transfer data between two SPI modules</span></div>
<div class="line">                                                    <span class="comment">//on the same chip, so it isn&#39;t primal if one of the interrupts conflict with the other one.</span></div>
<div class="line">                                                    <span class="comment">//(Didn&#39;t happen in these tests though. Not even with 4MHz SCK clock.)</span></div>
<div class="line">    <span class="keywordflow">while</span> (!(<a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].Completed &amp;&amp; <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].Completed)){}</div>
<div class="line"></div>
<div class="line">    </div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].<a class="code" href="struct___s_p_i___d_r_v.html#adca794807f12ed1014f0e08fbf17c695" title="Read data array, given terminating data (Slave). Allows a half-duplex data transmission where the mod...">listen_till</a>((RxData+60), 0,1);           <span class="comment">//Reversed roles.</span></div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].<a class="code" href="struct___s_p_i___d_r_v.html#a41173e3adcf94d40c1aaa34767bf638f" title="Write data array (Master). Allows a half-duplex data transmission where the module will transmit an a...">write_array</a>((uint16_t*)<span class="stringliteral">&quot;The night is dark, and full of terror.\0\0&quot;</span>,20,1);</div>
<div class="line">    <span class="keywordflow">while</span> (!(<a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].Completed &amp;&amp; <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].Completed)){}</div>
<div class="line"></div>
<div class="line">    </div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].<a class="code" href="struct___s_p_i___d_r_v.html#aa5e2288fb7202e84696e40a0e35b16b7" title="Write data array (Slave). The module will write the data to its TX_Buffer as a slave, ready to be read by a master.The size of the array is limited by the MAX_DATA_SIZE macro. It can either run on foreground, in which case the program will wait for the data to be transferred, or it can also run in background, but calling another method of the driver before this data is read will result in its loss. Therefore always wait for the Completed flag before moving on. . ">show_array</a>((uint16_t*)<span class="stringliteral">&quot;Lannisters send their regards.&quot;</span>,16,1);    <span class="comment">//These are practical for checking delay attributes. If those are</span></div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].<a class="code" href="struct___s_p_i___d_r_v.html#acacca74950b68d3dfeeb4b43d5a17234" title="Read data array (Master). Allows a half-duplex data transmission where the module will receive an arr...">read_array</a>(RxData+85,16,0);                                      <span class="comment">//too short and error on MSB of frames will occur.Or sometimes repeated frames.</span></div>
<div class="line">    <span class="keywordflow">while</span> (!(<a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].Completed &amp;&amp; <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].Completed)){}                       <span class="comment">//It rarely occurs with medium speed ports but right delay amounts are primordial for slow ports.</span></div>
<div class="line">    </div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].<a class="code" href="struct___s_p_i___d_r_v.html#aa5e2288fb7202e84696e40a0e35b16b7" title="Write data array (Slave). The module will write the data to its TX_Buffer as a slave, ready to be read by a master.The size of the array is limited by the MAX_DATA_SIZE macro. It can either run on foreground, in which case the program will wait for the data to be transferred, or it can also run in background, but calling another method of the driver before this data is read will result in its loss. Therefore always wait for the Completed flag before moving on. . ">show_array</a>((uint16_t*)<span class="stringliteral">&quot;Lannisters send their regards.&quot;</span>,16,1);</div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].<a class="code" href="struct___s_p_i___d_r_v.html#acacca74950b68d3dfeeb4b43d5a17234" title="Read data array (Master). Allows a half-duplex data transmission where the module will receive an arr...">read_array</a>(RxData+110,16,0);</div>
<div class="line">    <span class="keywordflow">while</span> (!(<a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].Completed &amp;&amp; <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].Completed)){}</div>
<div class="line">    </div>
<div class="line">    i=0x0A50;</div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].<a class="code" href="struct___s_p_i___d_r_v.html#a086ad89b79b23005b984e80dc5e65b92" title="Write data (Slave). The module will write the data to its TX_Buffer as a slave, ready to be read by a...">show</a>(&amp;i,1);</div>
<div class="line">    i=0xF5AF;</div>
<div class="line">    <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].<a class="code" href="struct___s_p_i___d_r_v.html#aaa043d94a20a9a8b13a062be3944e679" title="Exchange data (Master). Allows a full-duplex 16-bit data transfer where the module is the master...">exchange</a>(&amp;i,RxData+127);</div>
<div class="line">    <span class="keywordflow">while</span> (!(<a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[0].Completed &amp;&amp; <a class="code" href="group__group5.html#ga2365cce3281e8859c38a37edaced7e89" title="SPI driver instances. Variables defined on the driver structure, providing an Object Oriented user in...">SPI</a>[1].Completed)){}</div>
<div class="line"></div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">while</span> (1)    <span class="comment">//End of program </span></div>
<div class="line">    {</div>
<div class="line">    }</div>
<div class="line">}</div>
</div><!-- fragment --> </div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Mon Aug 19 2013 09:51:11 for SPI Driver by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.4 </li>
  </ul>
</div>
</body>
</html>
